"""
Core data structures for representing parsed Markdown content.
"""

from dataclasses import dataclass
from enum import Enum
from typing import Any, List, Optional


class ContentType(Enum):
    """Types of content that can be parsed from Markdown."""
    TEXT = "text"
    BULLET_LIST = "bullet_list"
    IMAGE = "image"
    VIDEO = "video"
    CODE_BLOCK = "code_block"
    ANIMATED_CONTENT = "animated_content"


@dataclass
class ContentNode:
    """Represents a single content element from Markdown."""
    type: ContentType
    data: Any
    metadata: Optional[dict] = None

    def __str__(self) -> str:
        return f"ContentNode({self.type.value}: {str(self.data)[:50]}...)"


@dataclass
class Section:
    """Represents a section in the document (corresponds to a slide)."""
    heading: str
    level: int  # 1 for #, 2 for ##
    content: List[ContentNode]
    
    def __str__(self) -> str:
        return f"Section(level={self.level}, heading='{self.heading}', content_count={len(self.content)})"

    @property
    def is_title_slide(self) -> bool:
        """Check if this section should be a title slide (level 1)."""
        return self.level == 1

    @property
    def is_content_slide(self) -> bool:
        """Check if this section should be a content slide (level 2)."""
        return self.level == 2


@dataclass
class DocumentStructure:
    """Represents the complete parsed Markdown document structure."""
    title: str
    sections: List[Section]
    metadata: Optional[dict] = None
    
    def __str__(self) -> str:
        return f"DocumentStructure(title='{self.title}', sections={len(self.sections)})"

    @property
    def title_sections(self) -> List[Section]:
        """Get all title slides (level 1 headings)."""
        return [s for s in self.sections if s.is_title_slide]

    @property
    def content_sections(self) -> List[Section]:
        """Get all content slides (level 2 headings)."""
        return [s for s in self.sections if s.is_content_slide]


@dataclass
class ImageContent:
    """Represents image content with metadata."""
    path: str
    alt_text: Optional[str] = None
    title: Optional[str] = None
    
    def __str__(self) -> str:
        return f"ImageContent(path='{self.path}', alt='{self.alt_text}')"


@dataclass
class BulletListContent:
    """Represents a bullet list."""
    items: List[str]
    
    def __str__(self) -> str:
        return f"BulletListContent({len(self.items)} items)"


@dataclass
class TextContent:
    """Represents plain text content."""
    text: str
    
    def __str__(self) -> str:
        return f"TextContent('{self.text[:50]}...')"


@dataclass
class VideoContent:
    """Represents video content with metadata."""
    path: str
    alt_text: Optional[str] = None
    title: Optional[str] = None
    poster_frame: Optional[str] = None  # Poster frame image path
    width: Optional[int] = None
    height: Optional[int] = None
    
    def __str__(self) -> str:
        return f"VideoContent(path='{self.path}', alt='{self.alt_text}')"


@dataclass
class CodeBlockContent:
    """Represents a code block."""
    code: str
    language: Optional[str] = None
    
    def __str__(self) -> str:
        return f"CodeBlockContent(lang='{self.language}', {len(self.code)} chars)"


@dataclass
class AnimatedContent:
    """Represents animated content with animation metadata."""
    content: 'ContentNode'  # The actual content to animate
    animation_type: str = "fadeIn"  # fadeIn, slideIn, appear, zoom, etc.
    duration: float = 1.0  # Animation duration in seconds
    delay: float = 0.0     # Delay before animation starts
    easing: str = "ease"   # CSS easing function
    direction: Optional[str] = None  # left, right, up, down (for slide animations)
    
    def __str__(self) -> str:
        return f"AnimatedContent({self.animation_type}, {self.duration}s, content={self.content.type.value})"


@dataclass
class AnimationConfig:
    """Global animation configuration."""
    default_duration: float = 1.0
    default_delay: float = 0.0
    default_easing: str = "ease"
    auto_animate: bool = True
    supported_animations: List[str] = None
    
    def __post_init__(self):
        if self.supported_animations is None:
            self.supported_animations = [
                # Entrance animations
                "fadeIn", "appear", "slideIn", "flyIn", "zoom", "bounce", "spiral", "wheel",
                # Emphasis animations  
                "pulse", "blink", "spin", "growShrink",
                # Exit animations
                "fadeOut", "slideOut", "flyOut", "zoomOut"
            ]